package com.kerbores.kop.module;

import org.nutz.mvc.Mvcs;
import org.nutz.mvc.View;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Views;
import org.nutz.mvc.ioc.provider.ComboIocProvider;

import com.kerbores.nutz.captcha.JPEGView;
import com.kerbores.nutz.captcha.JPEGViewMaker;
import com.kerbores.nutz.module.base.AbstractBaseModule;
import com.kerbores.nutz.module.base.NameSpace;
import com.kerbores.utils.entries.Result;

@Modules(scanPackage = true)
@IocBy(type = ComboIocProvider.class, args = { "*org.nutz.ioc.loader.json.JsonLoader", "config", "*org.nutz.ioc.loader.annotation.AnnotationIocLoader", "com.kerbores" })
@Ok("json")
@NameSpace("main")
@Fail("http:500")
@Views(JPEGViewMaker.class)
public class MainModule extends AbstractBaseModule {

	@Override
	public String _getNameSpace() {
		return "main";
	}

	@At
	public Result test() {
		return Result.success().addData("captcha", Mvcs.getReq().getSession().getAttribute(JPEGView.CAPTCHA));
	}

	@At
	public View captcha() {
		return new JPEGView(null, 5);
	}

}
